package com.typy.www.tpay.ui.itemview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.typy.www.tpay.R;
import com.typy.www.tpay.bean.vm.ActivicationVm;
import com.typy.www.tpay.ui.acitivity.WebActivity;
import com.typy.www.tpay.ui.view.CircleImageView;
import com.typy.www.tpay.util.ClassHoldUtil;
import com.typy.www.tpay.util.Logutil;
import com.typy.www.tpay.util.UpdataUiUtil;
import com.zhy.android.percent.support.PercentLinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 13799 on 2018/6/28.
 */

public class RecordActivicationItemView {
    View mView;
    ViewHolder holder;
    private Context mContext;

    public RecordActivicationItemView(Context context) {
        mContext = context;
        mView = LayoutInflater.from(context).inflate(R.layout.item_infomation, null);
        holder = new ViewHolder(mView);
    }

    public View getView() {
        return mView;
    }

    public void bind(final ActivicationVm vm, final int position, final int classType) {
        Logutil.print("RecordActivicationItemView");
        holder.imgDiv.setVisibility(View.VISIBLE);
        if (vm != null)
            if (classType == ClassHoldUtil.ActivicationRecord) {
                UpdataUiUtil.getDefaul().setText(vm.getFdToNickName(), holder.tvNickname)
                        .setText("UID:" + vm.getFdToUserId(), holder.tvUid)
                        .setText("分享分:" + vm.getFdSharePoint() + "分", holder.tvSharepoint)
                        .setText("余额:¥" + vm.getFdAmount(), holder.tvAmount)
                        .setText(vm.getFdCreateTime(), holder.tvTime);
                holder.llShare.setVisibility(View.VISIBLE);
            } else if (classType == ClassHoldUtil.TurnOutRecord || classType == ClassHoldUtil.ChangeIntoRecord) {
                Logutil.print("RecordActivicationItemView+" + vm.getFdAmount());
                UpdataUiUtil.getDefaul().setText(vm.getFdToNickName(), holder.tvNickname)
                        .setText("UID:" + vm.getFdToUserId(), holder.tvUid)
                        .setText("分享分:" + vm.getFdSharePoint() + "分", holder.tvSharepoint)
                        .setText("余额:¥" + vm.getFdAmount(), holder.tvAmount)
                        .setText(vm.getFdCreateTime(), holder.tvTime);
                holder.llShare.setVisibility(View.VISIBLE);
                Logutil.print("");

            } else if (classType == ClassHoldUtil.TurnOutDigiRECORD) {
//            holder.llTouxian1.setVisibility(View.GONE);
//            holder.llTouxian2.setVisibility(View.VISIBLE);
//                UpdataUiUtil.getDefaul().setText(vm.getFdToNickName(), holder.tvNickname2)
//                        .setText("UID:" + vm.getFdToUserId(), holder.tvUid2)
//                        .setText("Zpay数量：" + vm.getFdIconCount() + "个", holder.tvPhone2)
//                        .setText(vm.getFdCreateTime(), holder.tvTime2);
                UpdataUiUtil.getDefaul().setText(vm.getFdToNickName(), holder.tvNickname)
                        .setText("UID:" + vm.getFdToUserId(), holder.tvUid)
                        .setText("Zpay数量：" + vm.getFdIconCount() + "个", holder.tvPhone)
                        .setText(vm.getFdCreateTime(), holder.tvTime);
                holder.llShare.setVisibility(View.GONE);
                holder.tvPhone.setVisibility(View.VISIBLE);
                holder.tvPhone.setTextColor(mContext.getResources().getColor(R.color.text_darkcolor));
            } else if (classType == ClassHoldUtil.ShareRecord) {
                UpdataUiUtil.getDefaul().setText(vm.getFdNickName(), holder.tvNickname)
                        .setText("UID:" + vm.getFdId(), holder.tvUid)
                        .setText(vm.getFdCode(), holder.tvPhone)
                        .setText(vm.getFdCreateTime(), holder.tvTime);
                holder.llShare.setVisibility(View.GONE);
                holder.tvPhone.setVisibility(View.VISIBLE);
                holder.tvPhone.setTextColor(mContext.getResources().getColor(R.color.text_color_dark));
            }
        if (classType != ClassHoldUtil.ShareRecord)
            holder.llTouxian.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    WebActivity.show(mContext, "详情记录", vm.getFdUrl());
                }
            });
    }


    static class ViewHolder {
        @BindView(R.id.img_touxian)
        CircleImageView imgTouxian;
        @BindView(R.id.img_top)
        ImageView imgTop;
        @BindView(R.id.tv_nickname)
        TextView tvNickname;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_uid)
        TextView tvUid;
        @BindView(R.id.tv_phone)
        TextView tvPhone;
        @BindView(R.id.tv_sharepoint)
        TextView tvSharepoint;
        @BindView(R.id.tv_amount)
        TextView tvAmount;
        @BindView(R.id.ll_share)
        PercentLinearLayout llShare;
        @BindView(R.id.ll_touxian1)
        PercentLinearLayout llTouxian1;
        @BindView(R.id.img_div)
        ImageView imgDiv;
        @BindView(R.id.img_touxian2)
        CircleImageView imgTouxian2;
        @BindView(R.id.img_top2)
        ImageView imgTop2;
        @BindView(R.id.tv_nickname2)
        TextView tvNickname2;
        @BindView(R.id.tv_time2)
        TextView tvTime2;
        @BindView(R.id.tv_uid2)
        TextView tvUid2;
        @BindView(R.id.tv_phone2)
        TextView tvPhone2;
        @BindView(R.id.ll_touxian2)
        PercentLinearLayout llTouxian2;
        @BindView(R.id.img_div2)
        ImageView imgDiv2;
        @BindView(R.id.ll_touxian)
        PercentLinearLayout llTouxian;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
